package services

import (
	"peilian-api/app/global/databases/tables"
	"peilian-api/app/global/variable"
)

type SessionService struct{}

type Sri struct {
	SessionId int `json:"session_id" form:"session_id"`
}

type Sr struct {
	SessionId string `json:"session_id" form:"session_id" uri:"sessionId"`
}

type Sm struct {
	SessionId string `json:"session_id" form:"session_id" uri:"sessionId"`
	Mark      bool   `json:"mark" form:"mark"`
}

func FindSessionById(sessionId int) (*tables.Session, error) {
	var session tables.Session
	err := variable.DB.MySQL.Preload("User").Preload("Career").First(&session, "id = ?", sessionId).Error
	if err != nil {
		return nil, err
	}
	return &session, nil
}

func GetSessionById(sessionId int) (*tables.Session, error) {
	var session tables.Session
	err := variable.DB.MySQL.Preload("User").Preload("Career").First(&session, "id = ?", sessionId).Error
	if err != nil {
		return nil, err
	}
	return &session, nil
}

type SessionSync struct {
	IsSync bool `json:"is_sync" form:"is_sync"`
}
